home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / TransSkel++ 305 / Demos / MultiSkel++ / CZoomWindow.cp < prev    next >
Text File  |  1996-06-28  |  5KB  |  222 lines

  1. /*
  2.  * TransSkel++ CWindow subclass demonstration: CZoomWindow
  3.  * 
  4.  * This module is based entirely on Paul Dubois' ZoomRect module of 20 Dec 93:
  5.  *
  6.  * "This module handles a window in which successive randomly generated
  7.  * rectangles are smoothly interpolated into one another.  The display
  8.  * is white on black, which results in some interesting problems (see
  9.  * DrawGrowBox, for instance).  The display adjusts itself to the size
  10.  * of the window, so that the zoom series always lie entirely within
  11.  * the window.  Clicking the mouse in the window pauses the display until
  12.  * the button is released."
  13.  *
  14.  * The CZoomWindow class is a subclass of the CMultiSkelWindow class,
  15.  * which in turn is a kind of CWindow.  
  16.  *
  17.  * Modified by: fadushin 1/2/96
  18.  * Uses: TransSkel++ 3.00
  19.  */
  20.  
  21. #include "TransSkel++.h"
  22. #include "CZoomWindow.h"
  23. #include "MultiSkel++.h"
  24.  
  25.  
  26. #define    zoomSteps    15        /* # rects in interpolative series */
  27.  
  28. /*
  29.  * The ZoomSize of the window is the portRect - the right side scroll bars
  30.  */
  31. void
  32. CZoomWindow::SetZoomSize (void)
  33. {
  34. Rect    r;
  35.  
  36.     r = wind->portRect;
  37.     r.right -= 15;                /* don't use right edge */
  38.     sizeX = r.right;
  39.     sizeY = r.bottom;
  40. }
  41.  
  42.  
  43. /*
  44.  * return integer between zero and max (inclusive).  assumes max is
  45.  * non-negative.
  46.  */
  47.  
  48. short
  49. CZoomWindow::Rand(short max)
  50. {
  51. short    t;
  52.  
  53.     t = Random ();
  54.     if (t < 0) t = -t;
  55.     return (t % (max + 1));
  56. }
  57.  
  58.  
  59. /*
  60.  * Interpolate one rectangle smoothly into another.  Erase the previous
  61.  * series as the new one is drawn.
  62.  */
  63.  
  64. void
  65. CZoomWindow::ZoomRect (Rect *r1, Rect *r2)
  66. {
  67. short    r1left, r1top;
  68. short    l, t;
  69. short    j;
  70. short    hDiff, vDiff, widDiff, htDiff;
  71. short    r, b;
  72. short    rWid, rHt;
  73.  
  74.     //PenPat(gray);
  75.     r1left = r1->left;
  76.     r1top = r1->top;
  77.     hDiff = r2->left - r1left;    /* positive if moving to right */
  78.     vDiff = r2->top - r1top;        /* positive if moving down */
  79.     rWid = r1->right - r1left;
  80.     rHt = r1->bottom - r1top;
  81.     widDiff = (r2->right - r2->left) - rWid;
  82.     htDiff = (r2->bottom - r2->top) - rHt;
  83.     /*
  84.      * order of evaluation is important in the rect coordinate calculations.
  85.      * since all arithmetic is integer, you can't save time by calculating
  86.      * j/zoomSteps and using that - it'll usually be zero.
  87.      */
  88.     for (j = 1; j <= zoomSteps; j++)
  89.     {
  90.         FrameRect (&zRect[j-1]);                /* erase a rectangle */
  91.         l = r1left + (hDiff * j) / zoomSteps;
  92.         t = r1top + (vDiff * j) / zoomSteps;
  93.         r = l + rWid + (widDiff * j) / zoomSteps;
  94.         b = t + rHt + (htDiff * j) / zoomSteps;
  95.         SetRect (&zRect[j-1], l, t, r, b);
  96.         FrameRect (&zRect[j-1]);
  97.     }
  98. }
  99.  
  100.  
  101. /*
  102.  * Draw the grow box in white on black.  I used to do this by drawing the box and
  103.  * inverting it, but that doesn't work under System 7 which uses color tinges.
  104.  * Now I just draw the squares directly.  Ugh.
  105.  */
  106.  
  107. void
  108. CZoomWindow::DrawGrowBox(void)
  109. {
  110. Rect    r;
  111.     r = wind->portRect;
  112.     r.left = r.right - 15;
  113.     r.top = r.bottom - 15;
  114.     ++r.right;
  115.     ++r.bottom;
  116.     EraseRect (&r);
  117.     FrameRect (&r);
  118.     if (((WindowPeek) wind)->hilited)
  119.     {
  120.         r.right -= 6;
  121.         r.bottom -= 6;
  122.         OffsetRect (&r, 4, 4);
  123.         FrameRect (&r);
  124.         r.right -= 3;
  125.         r.bottom -= 3;
  126.         OffsetRect (&r, -1, -1);
  127.         EraseRect (&r);
  128.         FrameRect (&r);
  129.     }
  130. }
  131.  
  132.  
  133. void
  134. CZoomWindow::doClose(void)
  135. {
  136.    HideWindow(wind);
  137. }
  138.  
  139.  
  140.  
  141. /*
  142.  * just pause zoom display while mouse down
  143.  */
  144. void
  145. CZoomWindow::doMouseClick(Point pt, long t, short mods)
  146. {
  147.     while (StillDown ()) {  /* wait until mouse button released */ }
  148. }
  149.  
  150.  
  151. void
  152. CZoomWindow::doUpdate (Boolean resized)
  153. {
  154.    short i;
  155.  
  156.     EraseRect (&wind->portRect);
  157.     DrawGrowBox();
  158.     SetWindClip ();
  159.     for (i = 0; i < zoomSteps; ++i)
  160.         FrameRect (&zRect[i]);
  161.     ResetWindClip ();
  162.     if (resized)
  163.         SetZoomSize ();        /* adjust to new window size */
  164. }
  165.  
  166.  
  167. void
  168. CZoomWindow::doActivate (Boolean active)
  169. {
  170.  
  171.     DrawGrowBox ();
  172.     if (active)
  173.         DisableItem (gApp->editMenu.GetMenuHandle(), 0);
  174.     else
  175.         EnableItem (gApp->editMenu.GetMenuHandle(), 0);
  176.     DrawMenuBar ();
  177. }
  178.  
  179.  
  180.  
  181.  
  182. void
  183. CZoomWindow::doIdle (void)
  184. {
  185. short    i;
  186. Point    pt1, pt2;
  187. Rect    dstRect;
  188.  
  189.     SetPt (&pt1, Rand (sizeX), Rand (sizeY));    /* generate new rect */
  190.     SetPt (&pt2, Rand (sizeX), Rand (sizeY));    /* and zoom to it */
  191.     Pt2Rect (pt1, pt2, &dstRect);
  192.     SetWindClip ();            /* don't draw in right edge */
  193.     ZoomRect (&zSrcRect, &dstRect);
  194.     ResetWindClip ();
  195.     zSrcRect = dstRect;
  196. }
  197.  
  198.  
  199.  
  200. CZoomWindow::CZoomWindow(short resID)
  201.             :CMultiSkelWindow(resID, STORE_IN_HEAP, BRING_TO_FRONT, false)
  202. {
  203. short    i;
  204.  
  205.  
  206.     SetZoomSize ();
  207.     BackPat ((ConstPatternParam) &qd.black);
  208.     if (SkelQuery(skelQHasColorQD)){
  209.        RGBColor c;
  210.        
  211.        c.red   = 0xFFFF; // blood red
  212.        c.green = 0x0000;
  213.        c.blue  = 0x0000;
  214.        
  215.        RGBForeColor(&c);
  216.        }
  217.     PenMode (patXor);
  218.     SetRect (&zSrcRect, 0, 0, 0, 0);
  219.     for (i = 0; i < zoomSteps; ++i)        /* initialize rect array */
  220.         zRect[i] = zSrcRect;
  221. }
  222.